home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CommToolbox (modified) / Sources / CConnection.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  19.9 KB  |  995 lines  |  [TEXT/KAHL]

  1. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  2.  
  3.     CConnection.c
  4.     
  5.     CommToolbox connection class.
  6.     
  7.     SUPERCLASS = CBureaucrat.
  8.     
  9.     Original copyright © 1992-93 Romain Vignes. All rights reserved.
  10.     Modifications copyright © 1994-95 Ithran Einhorn. All rights reserved.
  11.     
  12. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  13.  
  14. #include <CommResources.h>                    /* Apple includes */
  15. #include <Connections.h>
  16.  
  17. #include <CBartender.h>                        /* TCL includes */
  18. #include <CCluster.h>
  19. #include <CError.h>
  20. #include <Constants.h>
  21. #include <TBUtilities.h>
  22. #include <TCLUtilities.h>
  23.  
  24. #include "CConnection.h"                    /* Other includes */
  25. #include "CFileTransfer.h"
  26. #include "CTermPane.h"
  27.  
  28. /* Constants & Macros */
  29.  
  30. #define CONN_STR_RES_ID        2100    /* Connection message resource ID */
  31.  
  32. #define NO_TOOL_STR_INDEX    1        /* No connection tool */
  33. #define BAD_TOOL_STR_INDEX    2        /* Bad connection tool */
  34. #define NO_REC_STR_INDEX    3        /* Connection record allocation error */
  35. #define CHOOSE_STR_INDEX    4        /* Tool setup error */
  36. #define OPEN_ERR_STR_INDEX    5        /* Error on opening */
  37. #define CLOSE_ERR_STR_INDEX 6        /* Error on closing */
  38. #define WAIT_ERR_STR_INDEX    7        /* Waiting impossible */
  39.  
  40. #define H_CHOOSE_POS        10        /* Setup dialog position */
  41. #define V_CHOOSE_POS        40
  42.  
  43. #define BREAK_DELAY            5        /* Approximately 80 ms */
  44.  
  45. #define FIRST_CONN_CMD        cmdConnChoose    /* First connection command */
  46. #define LAST_CONN_CMD        cmdConnListen    /* Last connection command */
  47.  
  48. #define RESET_ALRT_ID        2100    /* Reset alert resource ID */
  49.  
  50.  
  51. /* Application globals */
  52.  
  53. extern CBartender    *gBartender;
  54. extern CError        *gError;
  55.  
  56.  
  57. /* Class variables initialization */
  58.  
  59. CCluster *CConnection::cConnList = NULL;
  60.  
  61.  
  62.  
  63. /*
  64.  * cIsConnectionCmd
  65.  *
  66.  * Command related to the connection object
  67.  *
  68.  * theCmd:    command to analyse
  69.  *
  70.  * Return TRUE if the command is a connection command
  71.  *
  72.  */
  73.  
  74. Boolean CConnection::cIsConnectionCmd(long theCmd)
  75. {
  76.     return ((theCmd >= FIRST_CONN_CMD) && (theCmd <= LAST_CONN_CMD));
  77. }
  78.  
  79.  
  80. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  81.  
  82. /*
  83.  * cCheckToolName
  84.  *
  85.  * Checking existence of a tool by its name
  86.  *
  87.  * toolName:    name of the tool (Pascal string)
  88.  *
  89.  * Return cmGenericError if the tool is not present
  90.  *
  91.  */
  92.  
  93. OSErr CConnection::cCheckToolName(Str31 toolName)
  94. {
  95.     return(CMGetProcID(toolName));
  96. }    
  97.  
  98.  
  99. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  100.  
  101. /*
  102.  * cTestToolEvent
  103.  *
  104.  * Test if the event is related to a connection tool
  105.  *
  106.  * macEvent:    pointer on the event record
  107.  * theWindow:    pointer on the window record
  108.  *
  109.  * Return TRUE if the event is a terminal event
  110.  */
  111.  
  112. typedef struct    {
  113.     EventRecord    *theEvent;
  114.     WindowPtr    theWindow;
  115.     Boolean        isToolEvent;
  116. } TestParamRec;
  117.  
  118.  
  119.          /* Test routine */
  120.  
  121.         static void ConnEvtTest(CConnection *theConnection,TestParamRec *params)
  122.         {
  123.             if (params->isToolEvent == FALSE)
  124.                 params->isToolEvent = theConnection->DoEvent(params->theEvent,
  125.                     params->theWindow);
  126.         }
  127.  
  128.  
  129. Boolean CConnection::cTestToolEvent(EventRecord *macEvent,WindowPtr theWindow)
  130. {
  131.     TestParamRec params;
  132.     
  133.     params.theEvent = macEvent;
  134.     params.theWindow = theWindow;
  135.     params.isToolEvent = FALSE;
  136.     
  137.     if (cConnList == NULL)
  138.         return FALSE;
  139.     else    {
  140.         cConnList->DoForEach1((EachFunc1) ConnEvtTest,(long) ¶ms);
  141.         
  142.         return params.isToolEvent;
  143.     }
  144. }    
  145.  
  146. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  147.  
  148. /*
  149.  * cConnIdle
  150.  *
  151.  * Idle time for each connection object
  152.  *
  153.  *
  154.  */
  155.  
  156.          /* Idle routine for each connection object */
  157.  
  158.         static void    Conn_Idle(CConnection *theConn)
  159.         {
  160.             theConn->DoIdle();
  161.         }
  162.  
  163.  
  164. void CConnection::cConnIdle(void)
  165. {
  166.     if (cConnList != NULL)        /* List exists ? */
  167.         cConnList->DoForEach((EachFunc) Conn_Idle);
  168. }    
  169.  
  170.  
  171. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  172.  
  173. /*
  174.  * cInitManager
  175.  *
  176.  * Connection Manager Initialization
  177.  *
  178.  */
  179.  
  180. void CConnection::cInitManager(void)
  181. {
  182.     InitCM();
  183. }    
  184.  
  185.  
  186. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  187.  
  188. /*
  189.  * cGetCMVersion
  190.  *
  191.  * return the version of the Connection Manager
  192.  *
  193.  */
  194.  
  195. short CConnection::cGetCMVersion(void)
  196. {
  197.     return CMGetCMVersion();
  198. }    
  199.  
  200.  
  201. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  202.  
  203. /*
  204.  * IConnection
  205.  *
  206.  * Initialisation of the connection object
  207.  *
  208.  * aSupervisor:            object supervisor in the command chain
  209.  * toolName:            name of the connection tool to be used ("" -> défault)
  210.  * flags:(CM)            how to use the connection tool
  211.  * desiredSizes:(CM)    desired sizes of sending and receiving buffers
  212.  * refcon:(CM)            available for the application
  213.  * userData:(CM)        available for the application
  214.  *
  215.  * Parameters followed by CM are exact required parameters for creating a
  216.  * connection record.
  217.  *
  218.  */
  219.  
  220. void CConnection::IConnection(CBureaucrat *aSupervisor,Str31 toolName,
  221.                                 CMRecFlags flags,CMBufferSizes desiredSizes,
  222.                                 long refCon, long userData)
  223. {
  224.     ConnHandle    theConn;
  225.     OSErr        theErr;
  226.     Str31        tName;
  227.     short        toolProcID;
  228.     Boolean        savedAlloc;
  229.     
  230.     CBureaucrat::IBureaucrat(aSupervisor);    /* Initialize superclass */
  231.         
  232.     if (toolName[0] == 0)                    /* Default tool ? */
  233.     {
  234.         theErr = CRMGetIndToolName(classCM,1,tName);
  235.                 
  236.         if ((tName[0] == 0)    || (theErr != cmNoErr))         /* Error checking */
  237.             Failure(cmNoTools,SpecifyMsg(CONN_STR_RES_ID,NO_TOOL_STR_INDEX));
  238.             
  239.         toolProcID = cCheckToolName(tName);            /* Default tool ID */
  240.     }
  241.     else
  242.     {
  243.         toolProcID = cCheckToolName(toolName);        /* Specified tool ID */    
  244.     }
  245.         
  246.     if (toolProcID == cmGenericError)                /* No corresponding tool */
  247.     {
  248.         Failure(cmNoTools,SpecifyMsg(CONN_STR_RES_ID,BAD_TOOL_STR_INDEX));
  249.     }
  250.     
  251.     savedAlloc = SetAllocation(kAllocCanFail);
  252.         
  253.     theConn = CMNew(toolProcID,flags,desiredSizes,(long)this,userData);
  254.     
  255.     SetAllocation(savedAlloc);
  256.     
  257.     FailNIL(theConn);            /* Connection created ? */
  258.  
  259.     MoveHHi((Handle)theConn);    /* Heap fragmentation… */
  260.         
  261.     itsConn = theConn;
  262.         
  263.     if (cConnList == NULL)    {            /* first connection object ? */
  264.         cConnList = new(CCluster);
  265.         cConnList->ICluster();
  266.     }
  267.     
  268.     cConnList->Add(this);                /* Connection addition */
  269.         
  270.     this->connOpen = FALSE;    
  271.     this->active = FALSE;
  272.     
  273.     #ifdef __USETHREADS__
  274.     if (CThread::cIsPresent())
  275.     {
  276.         itsIdleThread = new(CThread);
  277.         itsIdleThread->IThread(kCooperativeThread, (ThreadEntryProcPtr)cOneConnIdle, this);
  278.     }
  279.     #endif
  280. }
  281.  
  282.  
  283. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  284.  
  285. /*
  286.  * Dispose
  287.  *
  288.  * Dispose of a connection object
  289.  *
  290.  */
  291.  
  292. void CConnection::Dispose(void)
  293. {
  294.     ASSERT(cConnList != NULL);
  295.     
  296.     #ifdef __USETHREADS__
  297.     if (CThread::cIsPresent())
  298.     {
  299.         itsIdleThread->Dispose();
  300.     }
  301.     #endif
  302.     
  303.     cConnList->Remove(this);            /* Dispose of the Connection */
  304.     
  305.     if (cConnList->IsEmpty())
  306.         ForgetObject(cConnList);        /* Dispose of the cluster */
  307.  
  308.     CMDispose(itsConn);                    /* Dispose of the connection record */
  309.     itsConn = NULL;
  310.         
  311.     inherited::Dispose();                /* Pass message to its superclass */
  312. }
  313.  
  314.  
  315. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  316.  
  317. /*
  318.  * UpdateMenus
  319.  *
  320.  * Connection related menus updating
  321.  *
  322.  */
  323.  
  324. void CConnection::UpdateMenus(void)
  325. {
  326.     
  327.     gBartender->EnableCmd(cmdConnChoose);        /* Setup command */
  328.     
  329.     gBartender->EnableCmd(cmdConnReset);        /* Connection reset */
  330.     
  331.     if (this->IsOpen())    {                        /* Connection open ? */
  332.         gBartender->EnableCmd(cmdConnClose);
  333.         gBartender->EnableCmd(cmdConnBreak);
  334.     }
  335.     else    {
  336.         gBartender->EnableCmd(cmdConnOpen);
  337.         gBartender->EnableCmd(cmdConnListen);
  338.     }
  339. }
  340.  
  341.  
  342. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  343.  
  344. /*
  345.  * DoCommand
  346.  *
  347.  * Handle connection related commands
  348.  *
  349.  * theCommand:    command to be executed
  350.  *
  351.  */
  352.  
  353. void CConnection::DoCommand(long theCommand)
  354. {
  355.     switch (theCommand)    {        
  356.     
  357.         case cmdConnChoose:        /* Connection tool setup */
  358.             this->ConnectionChoose();
  359.             break;
  360.             
  361.         case cmdConnOpen:        /* Connection opening */
  362.             this->OpenConnection(FALSE,NULL,0L);
  363.             break;
  364.             
  365.         case cmdConnListen:        /* Connection listening */
  366.             this->ListenConnection(FALSE,NULL,0L);
  367.             break;
  368.             
  369.         case cmdConnClose:        /* Connection waiting */
  370.             this->CloseConnection(FALSE,NULL,0L,TRUE);
  371.             break;
  372.             
  373.         case cmdConnReset:        /* Connection reset */
  374.             this->Reset();
  375.             break;
  376.             
  377.         case cmdConnBreak:        /* BREAK signal send */
  378.             this->SendBreak();
  379.             break;
  380.             
  381.         default:                /* Unknown command */
  382.             break;
  383.     }
  384. }
  385.  
  386.  
  387. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  388.  
  389. /*
  390.  * DoEvent
  391.  *
  392.  * Connection tool related events
  393.  *
  394.  * theEvent:    Pointeur on the event
  395.  * theWindow:    Window associated with the event
  396.  *
  397.  * Return TRUE if it is a tool event
  398.  *
  399.  */
  400.  
  401. Boolean CConnection::DoEvent(EventRecord *theEvent,WindowPtr theWindow)
  402. {
  403.     Boolean        isToolEvent;
  404.     ConnHandle    theConn;
  405.     
  406.     isToolEvent = FALSE;
  407.     
  408.     theConn = (ConnHandle) GetWRefCon(theWindow);
  409.     
  410.     if (theConn == itsConn)    {            /* Tool window ? */
  411.         CMEvent(itsConn,theEvent);
  412.         isToolEvent = TRUE;
  413.     }
  414.     
  415.     return isToolEvent;
  416. }    
  417.  
  418. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  419.  
  420. /*
  421.  * ConnectionChoose
  422.  *
  423.  * Connection tool setup
  424.  *
  425.  */
  426.  
  427. void CConnection::ConnectionChoose(void)
  428. {
  429.     short        retCode;
  430.     Point        where;
  431.     ConnHandle    hConn;
  432.     
  433.     hConn = this->itsConn;
  434.     
  435.     SetPt(&where,H_CHOOSE_POS,V_CHOOSE_POS);    /* Dialog position */
  436.                                                 
  437.     retCode = CMChoose(&hConn,where,NULL);
  438.     
  439.     this->itsConn = hConn;
  440.  
  441.     switch (retCode)    {        
  442.         case chooseCancel:        /* Forget changes */
  443.             break;
  444.             
  445.         case chooseOKMajor:        /* Changed tool */
  446.         
  447.          // if we belong to a terminal pane, get its file transfer object
  448.          if (member(itsSupervisor, CTermPane))
  449.          {
  450.           CFileTransfer    *itsFileTransfer = nil;
  451.           
  452.          itsFileTransfer = ((CTermPane *)itsSupervisor)->GetFileTransfer ();
  453.          
  454.          if (itsFileTransfer)
  455.                itsFileTransfer->AddSearch();
  456.          }
  457.          // fall through to chooseOKMinor processing
  458.      
  459.         case chooseOKMinor:        /* Same tool, changed config */
  460.         
  461.             active = FALSE;
  462.             Activate();
  463.         
  464.             itsSupervisor->Notify(NULL);     /* Document updated */
  465.             
  466.             break;
  467.             
  468.         default:                /* Unknown code (error) */
  469.             SysBeep(3);
  470.             gError->PostAlert(CONN_STR_RES_ID,CHOOSE_STR_INDEX);
  471.             break;    
  472.     }
  473. }
  474.  
  475.  
  476. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  477.  
  478. /*
  479.  * SetConfig
  480.  *
  481.  * Connection configuration change
  482.  *
  483.  * theConfig:    new configuration (C string)
  484.  *
  485.  * Return:        negative value: error (-1 -> unknown error)
  486.  *                positive value: stop index of the parser
  487.  *                cmNoErr if everything is OK
  488.  *
  489.  */
  490.  
  491. short CConnection::SetConfig(char *theConfig)
  492. {
  493.     short retCode;
  494.     
  495.     retCode = CMSetConfig(itsConn,theConfig);
  496.     
  497.     return retCode;
  498. }    
  499.  
  500.  
  501. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  502.  
  503. /*
  504.  * GetToolName
  505.  *
  506.  * Return the name of the current tool
  507.  *
  508.  * toolName:    tool name (Pascal string)
  509.  *
  510.  */
  511.  
  512. void CConnection::GetToolName(Str31 toolName)
  513. {
  514.     SignedByte    savedState;
  515.     
  516.     savedState = (SignedByte)HGetState((Handle)itsConn);
  517.     HLock((Handle)itsConn);
  518.  
  519.     CMGetToolName((*itsConn)->procID,toolName);
  520.     
  521.     HSetState((Handle)itsConn,(char)savedState);
  522. }    
  523.  
  524.  
  525. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  526.  
  527. /*
  528.  * AddSearch
  529.  *
  530.  * Add auto download search pattern
  531.  *
  532.  * 
  533.  *
  534.  */
  535.  
  536. long CConnection::AddSearch(Str255 theString, CMSearchFlags flags, CommSearchPtr callBack)
  537. {
  538.  if (callBack == nil)
  539.      callBack = (CommSearchPtr)DefAutoRecCallback;
  540.      
  541.  return CMAddSearch(itsConn, theString, flags, callBack);
  542. }
  543.  
  544. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  545.  
  546. /*
  547.  * RemoveSearch
  548.  *
  549.  * Remove auto download search pattern
  550.  *
  551.  */
  552.  
  553. void CConnection::RemoveSearch(long refNum)
  554. {
  555.  CMRemoveSearch(itsConn, refNum);
  556. }
  557.  
  558. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  559.  
  560. /*
  561.  * ClearSearch
  562.  *
  563.  * Clear all auto download search patterns
  564.  *
  565.  *
  566.  */
  567.  
  568. void CConnection::ClearSearch(void)
  569. {
  570.  CMClearSearch(itsConn); 
  571. }
  572.  
  573. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  574.  
  575. /*
  576.  * GetConfig
  577.  *
  578.  * Return a C string describing the current config of the connection
  579.  *
  580.  * Return a pointer on the string
  581.  *
  582.  */
  583.  
  584. Ptr CConnection::GetConfig(void)
  585. {
  586.     return(CMGetConfig(itsConn));
  587. }    
  588.  
  589.  
  590. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  591.  
  592. /*
  593.  * getStatus
  594.  *
  595.  * Return the connection status
  596.  *
  597.  * sizes:    Buffers sizes (sortie)
  598.  * flags:    Connection status (sortie)
  599.  *
  600.  * Return an error code
  601.  *
  602.  */
  603.  
  604. OSErr CConnection::getStatus(CMBufferSizes *sizes,CMStatFlags *flags)
  605. {
  606.     return(CMStatus(itsConn,*sizes,flags));
  607. }    
  608.  
  609.  
  610. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  611.  
  612. /*
  613.  * OpenConnection
  614.  *
  615.  * Connection opening
  616.  *
  617.  * async:        Opening mode (synchrone or asynchrone)
  618.  * completor:    asynchrone callback
  619.  * timeOut:        time period within which the opening must be completed
  620.  *
  621.  */
  622.  
  623. void CConnection::OpenConnection(Boolean async,CommProcPtr completor,long timeOut)
  624. {
  625.     OSErr    theErr;
  626.     
  627.     theErr = CMOpen(itsConn,async,completor,timeOut);
  628.     
  629.     if (theErr == cmNoErr)    {
  630.         this->connOpen = TRUE;
  631.         BroadcastChange(connOpenInd,NULL);
  632.     }
  633. }    
  634.  
  635.  
  636. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  637.  
  638. /*
  639.  * ListenConnection
  640.  *
  641.  * Connection listening
  642.  *
  643.  * async:        Listening mode (synchrone or asynchrone)
  644.  * completor:    asynchrone callback
  645.  * timeOut:        time period within which the listening must be completed
  646.  *
  647.  */
  648.  
  649. void CConnection::ListenConnection(Boolean async,CommProcPtr completor,long timeOut)
  650. {
  651.     OSErr    theErr;
  652.     
  653.     theErr = CMListen(itsConn,async,completor,timeOut);
  654. }    
  655.  
  656.  
  657. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  658.  
  659. /*
  660.  * CloseConnection
  661.  *
  662.  * Connection closing
  663.  *
  664.  * async:        Closing mode (synchrone or asynchrone)
  665.  * completor:    asynchrone callback
  666.  * timeOut:        time period within which the closing must be completed
  667.  * now:            immediately closing
  668.  *
  669.  */
  670.  
  671. void CConnection::CloseConnection(Boolean async,CommProcPtr completor,long timeOut,
  672.                                     Boolean now)
  673. {
  674.     OSErr theErr;
  675.  
  676.     if (*itsConn != nil)
  677.     {                                            /* have a good connection? */
  678.         if (CMValidate(itsConn) == false)
  679.         {
  680.             theErr = CMAbort(itsConn);                                /* just in case, abort open call */
  681.             theErr = CMIOKill(itsConn,cmDataIn);                    /* ...and, pending read */
  682.             theErr = CMIOKill(itsConn,cmDataOut);                    /* ...and, pending write */
  683.             theErr = CMClose(itsConn,async,completor,timeOut,now);    /* ...close, it */
  684.         }
  685.         else
  686.             theErr = cmUnknownError;
  687.     }
  688.     else
  689.         theErr = nilHandleErr;
  690.     
  691.     if (theErr == cmNoErr)    {
  692.         this->connOpen = FALSE;
  693.         BroadcastChange(connCloseInd,NULL);
  694.     };
  695. }    
  696.  
  697.  
  698. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  699.  
  700. /*
  701.  * IsOpen
  702.  *
  703.  * Connection opening test
  704.  *
  705.  * Return TRUE if the connection is open
  706.  *
  707.  */
  708.  
  709. Boolean CConnection::IsOpen(void)
  710. {
  711.     CMBufferSizes    sizes;
  712.     CMStatFlags        flags;
  713.     OSErr            theErr;
  714.     
  715.     theErr = this->getStatus(&sizes,&flags);
  716.     
  717.     if (theErr == cmNoErr)
  718.         if (flags & cmStatusOpen)        /* Connection open ? */
  719.             return TRUE;
  720.         else
  721.             return FALSE;
  722.     else
  723.         return FALSE;
  724. }    
  725.  
  726.  
  727. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  728.  
  729. /*
  730.  * DataAvail
  731.  *
  732.  * Data available
  733.  *
  734.  * Return the number of available characters
  735.  *
  736.  */
  737.  
  738. long CConnection::DataAvail(void)
  739. {
  740.     CMBufferSizes    sizes;
  741.     CMStatFlags        flags;
  742.     OSErr            theErr;
  743.     
  744.     theErr = this->getStatus(&sizes,&flags);
  745.     
  746.     if (theErr == cmNoErr)
  747.         if (flags & cmStatusDataAvail)        /* Data available ? */
  748.             return sizes[cmDataIn];        /* Return receiving buffer size */
  749.         else
  750.             return 0;
  751.     else
  752.         return 0;
  753. }    
  754.  
  755.  
  756. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  757.  
  758. /*
  759.  * DataRead
  760.  *
  761.  * Reading of available data
  762.  *
  763.  * inBuffer:    Receiving buffer
  764.  * buffSize:    Number of chars to read
  765.  * async:        Reading mode (asynchrone or synchrone)
  766.  * completor:    Reading callback
  767.  * timeOut:        time period within which the reading must be completed
  768.  * flags:        end-of-message indicator
  769.  *
  770.  * Return an error code
  771.  *
  772.  */
  773.  
  774. OSErr CConnection::DataRead(Ptr inBuffer,long *buffSize,Boolean async,
  775.                             CommProcPtr completor,long timeOut,CMFlags *flags,CMChannel channel)
  776. {
  777.  CMBufferSizes    sizes;
  778.  CMStatFlags    statFlags;
  779.  
  780.  getStatus (&sizes, &statFlags);
  781.      
  782.  return ((statFlags & cmStatusDRPend) == 0L ?
  783.           CMRead(itsConn,inBuffer,buffSize,channel,async,completor,timeOut,flags) : 0);
  784. }    
  785.  
  786.  
  787. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  788.  
  789. /*
  790.  * DoIdle
  791.  *
  792.  * Idle time of the application
  793.  *
  794.  */
  795.  
  796. void CConnection::DoIdle(void)
  797. {    
  798.     CMIdle(itsConn);
  799.     
  800.     if (!(this->IsOpen()) && this->connOpen)    {
  801.         this->connOpen = FALSE;
  802.         BroadcastChange(connCloseInd,NULL);
  803.     };
  804. }                                        
  805.  
  806. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  807.  
  808. /*
  809.  * cOneConnIdle
  810.  * 
  811.  * terminal idle time
  812.  *
  813.  */
  814.  
  815. pascal void    *CConnection::cOneConnIdle (void *threadParam)
  816. {
  817.     CConnection *aConn = (CConnection *)threadParam;
  818.     
  819.     #ifdef __USETHREADS__
  820.     for (;;)
  821.     {
  822.         ThreadBeginCritical();
  823.     #endif
  824.  
  825.         aConn->DoIdle();    
  826.  
  827.     #ifdef __USETHREADS__
  828.         ThreadEndCritical();
  829.         YieldToAnyThread();
  830.     }
  831.     #endif
  832.  
  833.     return nil;
  834. }
  835.  
  836. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  837.  
  838. /*
  839.  * DataWrite
  840.  *
  841.  * Data writing
  842.  *
  843.  * inBuffer:    Sending buffer
  844.  * buffSize:    Number of chars to send
  845.  * async:        Writing mode (synchrone or asychrone)
  846.  * completor:    Asynchrone writing callback
  847.  * timeOut:        time period within which the writing must be completed
  848.  * flags:        end-of-message indicator
  849.  *
  850.  * Return an error code
  851.  *
  852.  */
  853.  
  854. OSErr CConnection::DataWrite(Ptr inBuffer,long *buffSize,Boolean async,
  855.                             CommProcPtr completor,long timeOut,CMFlags flags)
  856. {
  857.     return (CMWrite(itsConn,inBuffer,buffSize,cmData,async,completor,timeOut,flags));
  858. }    
  859.  
  860.  
  861. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  862.  
  863. /*
  864.  * Activate
  865.  *
  866.  * Connection activation
  867.  *
  868.  */
  869.  
  870. void CConnection::Activate(void)
  871. {
  872.     if (!active)
  873.     {
  874.         CMActivate(itsConn,TRUE);
  875.         active = TRUE;
  876.     }
  877. }                                        
  878.  
  879.  
  880. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  881.  
  882. /*
  883.  * Deactivate
  884.  *
  885.  * Connection desactivation
  886.  *
  887.  */
  888.  
  889. void CConnection::Deactivate(void)
  890. {
  891.     if (active)
  892.     {
  893.         CMActivate(itsConn,FALSE);
  894.         active = FALSE;
  895.     }
  896. }                                        
  897.  
  898.  
  899. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  900.  
  901. /*
  902.  * Reset
  903.  *
  904.  * Connection reset
  905.  *
  906.  */
  907.  
  908. void CConnection::Reset(void)
  909. {
  910.     short    response;
  911.     
  912.     PositionDialog('ALRT', RESET_ALRT_ID);
  913.     
  914.     InitCursor();
  915.     
  916.     response = Alert(RESET_ALRT_ID, NULL);
  917.         
  918.     if (response == answerNO)
  919.         CMReset(itsConn);
  920. }                                        
  921.  
  922.  
  923. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  924.  
  925. /*
  926.  * SendBreak
  927.  *
  928.  * BREAK signal sending
  929.  *
  930.  */
  931.  
  932. void CConnection::SendBreak(void)
  933. {
  934.     CMBreak(itsConn,BREAK_DELAY,FALSE,NULL);
  935. }                                        
  936.  
  937.  
  938. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  939.  
  940. /*
  941.  * GetEnvirons
  942.  *
  943.  * Return the connection environs
  944.  *
  945.  * theEnvirons: Pointer on the environs record
  946.  *
  947.  * Return an error code
  948.  *
  949.  */
  950.  
  951. OSErr CConnection::GetEnvirons(ConnEnvironRecPtr theEnvirons)
  952. {
  953.     return(CMGetConnEnvirons(itsConn,theEnvirons));
  954. }    
  955.  
  956. /*
  957.  * get the connection handle
  958.  */
  959.  
  960. ConnHandle CConnection::GetConnHandle (void)
  961. {
  962.  return itsConn;
  963. }
  964.  
  965. /*******************************************************************
  966. *    DefAutoRecCallback    - Sets the file transfer flag if an auto-
  967. *                    receive string was found.
  968. *
  969. *        theConn            - which connection tool found it
  970. *        data            - ptr to last character in the match
  971. *        refNum            - which search was found
  972. *
  973. **********************************************************************/
  974.  
  975. pascal void CConnection::DefAutoRecCallback(ConnHandle theConn, Ptr data, long refNum)
  976. {
  977.  CConnection    *theConnection = (CConnection *)CMGetRefCon (theConn);
  978.  CFileTransfer    *itsFileTransfer = nil;
  979.  
  980.  // if we belong to a terminal pane, get its file transfer object
  981.  if (member(theConnection->itsSupervisor, CTermPane))
  982.      itsFileTransfer = ((CTermPane *)(theConnection->itsSupervisor))->GetFileTransfer ();
  983.  
  984.  // We can't call _FTStart or _CMRemoveSearch here as     
  985.  // this proc might be called from Interrupt level        
  986.  
  987.  if (itsFileTransfer)
  988.  {
  989.   if (itsFileTransfer->GetSearchNum () == refNum)
  990.         itsFileTransfer->SetAutoDownload (true);        // Set the flag to call FTStart in Idle
  991.  }
  992. } // DefAutoRecCallBack    
  993.  
  994. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  995.